package com.zmc.coupon.controller;

import java.util.List;

import com.zmc.common.annotation.PreventRepeatSubmit;
import com.zmc.common.enums.RequestSourceEnum;
import com.zmc.common.utils.poi.ExcelUtil;
import com.zmc.coupon.infrastructure.bean.query.CouponHistoryQuery;
import com.zmc.coupon.infrastructure.bean.vo.CouponHistoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.zmc.coupon.infrastructure.entity.CouponHistoryEntity;
import com.zmc.coupon.infrastructure.service.CouponHistoryService;
import com.zmc.common.utils.R;

import javax.servlet.http.HttpServletResponse;


/**
 * 优惠券领取历史记录
 *
 * @author zmc
 * @email
 * @date 2024-10-09 14:59:36
 */
@RestController
@RequestMapping("/coupon/history")
public class CouponHistoryController {


    @Autowired
    private CouponHistoryService couponHistoryService;

    /**
     * 后台商户列表
     */
    @RequestMapping("/page")
    public R page(CouponHistoryQuery query) {
        return R.page(couponHistoryService.queryPage(query));
    }

    /**
     * 商城用户列表展示
     */
    @RequestMapping("/list")
    public R list(@RequestBody CouponHistoryQuery query) {
        return R.ok(couponHistoryService.queryPage(query));
    }


    /**
     * 导出列表
     */
    @PostMapping("/export")
    @PreventRepeatSubmit(lockByPerson = true, source = RequestSourceEnum.MANAGE)
    public void export(HttpServletResponse response, CouponHistoryQuery query) {
        List<CouponHistoryEntity> list = couponHistoryService.queryList(query);
        ExcelUtil<CouponHistoryEntity> util = new ExcelUtil<>(CouponHistoryEntity.class);
        util.exportExcel(response, list, "优惠券领取历史记录数据");
    }


    /**
     * 信息
     */
    @PostMapping("/info")
    public R info(@RequestBody CouponHistoryVo vo) {
        return R.ok(couponHistoryService.getById(vo.getId()));
    }

}
